package com.jcfk.eam.controller.mould;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.enums.AvailableStatus;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.business.utils.DataBindHelper;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import com.jcfk.eam.domain.dto.mould.EamAssetMouldProductDTO;
import com.jcfk.eam.domain.query.mould.EamAssetMouldProductQuery;
import com.jcfk.eam.service.mould.EamAssetMouldProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import com.jcfk.common.core.utils.ExcelUtils;
/**
 * 模具资产关联产品
 *
 * @author yrl
 * @email 
 * @date 2025-07-28
 */
@Api(tags = {"模具资产关联产品管理"})
@RestController
@RequestMapping("eamassetmouldproduct")
public class EamAssetMouldProductController {
    @Autowired
    private EamAssetMouldProductService eamAssetMouldProductService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<EamAssetMouldProductQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询模具资产关联产品")
    @PostMapping("/queryByPage")
    public RetPage<EamAssetMouldProductDTO> queryByPage(@RequestBody ReqPageParam<EamAssetMouldProductQuery> requestParam) {
        DataPage<EamAssetMouldProductDTO> page = new DataPage<EamAssetMouldProductDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            EamAssetMouldProductDTO.class);
        page = eamAssetMouldProductService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     *  模具资产关联产品
     * 根据id 查询详情
     */
    @ApiOperation("查询模具资产关联产品")
    @GetMapping("/get/{id}")
    public RetResult<EamAssetMouldProductDTO> get(@PathVariable("id") String id) {
            EamAssetMouldProductDTO item = eamAssetMouldProductService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理模具资产关联产品
     */
    @ApiOperation("保存模具资产关联产品")
    @PostMapping("/save")
    @RequestLogHeader(modular = "模具资产关联产品管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid EamAssetMouldProductDTO eamAssetMouldProduct) {
        // 数据校验
        RetResult ret = eamAssetMouldProductService.isValid(eamAssetMouldProduct);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(eamAssetMouldProduct.getId())){
            // 新增
            eamAssetMouldProductService.insert(eamAssetMouldProduct);
        } else{
            // 更新
            eamAssetMouldProductService.update(eamAssetMouldProduct);
        }
        return RetResult.ok();

    }

    /**
     *  批量删除模具资产关联产品
     */
    @ApiOperation("批量删除模具资产关联产品")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "模具资产关联产品管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody EamAssetMouldProductDTO eamAssetMouldProduct) {
        return RetResult.ok(eamAssetMouldProductService.logicDeleteList(eamAssetMouldProduct));
    }





    /**
     *  删除模具资产关联产品
     */
    @ApiOperation("删除模具资产关联产品")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "模具资产关联产品管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        eamAssetMouldProductService.deleteItem(id);
        return RetResult.ok();
    }
}
